class Solution:
    def findXSum(self, nums: List[int], k: int, x: int) -> List[int]:
        n = len(nums)
        def func(arr):
            cnt = Counter(arr)
            cnt = sorted(cnt.items(), key = lambda x:(-x[1], -x[0]))
            s = 0
            for k, v in cnt[:x]:
                s += k * v
            return s 
        ans = []
        for i in range(n - k + 1):
            ans.append(func(nums[i : i + k]))
        return ans